<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- <script>
        let xhr = new XMLHttpRequest();
        xhr.open('GET','https://www.baidu.com/',true);
        xhr.send();
    </script> -->

    <script>
        let xhr = new XMLHttpRequest();
        xhr.onload = e => {
            console.log('request success');
        }
        // 请求结束
        xhr.onloadend = e => {
            console.log('request loadend');
        };
        // 请求出错
        xhr.onerror = e => {
            console.log('request error');
        };
        // 请求超时
        xhr.ontimeout = e => {
            console.log('request timeout');
        };
        xhr.timeout = 0;
        // 初始化请求
        xhr.open('GET/POST/DELETE/...', '/https://www.baidu.com/', true || false);
        xhr.responseType = '';
        // 设置请求头
        xhr.setRequestHeader('', '');
        // 发送请求
        xhr.send(null || new FormData || 'a=1&b=2' || 'json字符串');
    </script>

</body>

</html>